import 'package:flutter/material.dart';

import 'request.dart';

/// 添加参数，如用于替换各种状态的图片，文案和提示文案
class CommonRequestStateCallback with RequestStateCallback {
  const CommonRequestStateCallback(
      {this.emptyText = "暂无数据~", this.retryText = "点击重试"});

  final String retryText;
  final String emptyText;

  @override
  Widget emptyWidget(BuildContext context, RetryFunction retryFunction) {
    return Container(
      color: Colors.redAccent,
      alignment: Alignment.center,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text("$emptyText"),
          RaisedButton(
            onPressed: retryFunction,
            child: Text(retryText),
          )
        ],
      ),
    );
  }

  @override
  Widget errorWidget(BuildContext context, retryFunction, [Object error]) {
    return Container(
//      width: 200,
//      height: 200,
      color: Colors.redAccent,
      alignment: Alignment.center,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text("$emptyText:${error?.toString()}"),
          RaisedButton(
            onPressed: retryFunction,
            child: Text(retryText),
          )
        ],
      ),
    );
  }

  @override
  Widget loadingWidget(BuildContext context) {
    return Center(
      child: CircularProgressIndicator(),
    );
  }
}
